﻿using MediatR;
using W.Purchase.API.Application.Command.ClientCommand;
using W.Purchase.Domain;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.ClientCommandHandler
{
    public class ContactAddCommandHandler : IRequestHandler<ContactAddCommand, int>
    {
        private readonly IContactRepository repository;
        public ContactAddCommandHandler(IContactRepository repository)
        {
            this.repository = repository;
        }
        public async Task<int> Handle(ContactAddCommand request, CancellationToken cancellationToken)
        {
            request.CreateTime = DateTime.Now;
            return await repository.AddAsync(new Contact()
            {

                ContactName= request.ContactName,
                ContactAddress=request.ContactAddress,
                ContactPhone=request.ContactPhone

            });
        }
    }
}
